package cn.tedu.charging.order.dao.repository.impl;

import cn.tedu.charging.order.constant.OrderStatusConstant;
import cn.tedu.charging.order.dao.mapper.OrderSuccessMapper;
import cn.tedu.charging.order.dao.repository.OrderRepository;
import cn.tedu.charging.order.pojo.po.ChargingBillSuccessPO;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class OrderRepositoryImpl implements OrderRepository {
    @Autowired
     private OrderSuccessMapper orderSuccessMapper;
    @Override
    public void updateOrderStatusFromProcess2ExceptionEnd(String orderNo) {
        //更新目标的值 set bill_status = 3  (异常结束) 在 entity
        ChargingBillSuccessPO chargingBillSuccessPO = new ChargingBillSuccessPO();
        //bill_status = 3
        chargingBillSuccessPO.setBillStatus(OrderStatusConstant.ORDER_STATUS_EXCEPTION_END);
        //UpdateWrapper 更新的条件 where bill_id = orderNo and bill_status = 1 (充电中)
        UpdateWrapper updateWrapper  = new UpdateWrapper();
        //bill_id = orderNo
        updateWrapper.eq("bill_id",orderNo);
        //bill_status = 1
        updateWrapper.eq("bill_status", OrderStatusConstant.ORDER_STATUS_PROGRESS);
        orderSuccessMapper.update(chargingBillSuccessPO,updateWrapper);
    }
}
